

*Kayran and Nadler - Political Behavior*
*Local alien enfranchisement and external efficacy perceptions: 
* intended and unintended effects on non-citizens and citizens*

cd "C:\Users\ENK\Desktop\Working directory"

mvdecode _all, mv(-1=. \ -2=. \ -3=. \ -4=. \ -5=. \ -6=. \ -7=. \ -8=.)

*idpers // identification of person
* canton // identifies the canton of the household
* ofs_ // identifies the municipality of the household

tab mvoting
label define aes 0 "None AE" 1 "AE"
label values mvoting aes

*******************************************************
*** Identifying the sample and population of interest:
********************************************************

** Identify "natives"
tab nat_1_
generate swiss = 0
replace swiss = 1 if nat_1_ == 8100 | nat_2_ == 8100 | nat_3_ == 8100
tab swiss
recode swiss (0=.) if nat_1_ ==. & nat_2_ ==. & nat_3_ ==.
tab swiss
tab swiss syear, missing
*** NNI -if Swiss = 0 


* Identify NI*

* d161_ Swiss since birth
tab d161_ syear // if 1(yes) -- natives if 2 (no): either NI or NNI
generate swiss_birth = d161_
** run this code 5 times 
*replace swiss_birth = swiss_birth[_n+1] if swiss_birth == .
*generate swiss_birth_v2 = d161_
*by idpers: gen swiss_birth_v2 = d161_[_n+1] if d161_ ==.
*xtset idpers syear
*bysort idpers: gen nativelag = L.imgroup

** identifying those who have Swiss citizenship from birth
generate frombirth = d161_
bysort idpers (frombirth): replace frombirth = frombirth[1]

***********************************
xtset idpers syear
tab idpers disagree if imgroup_v2 != L.imgroup_v2 & imgroup_v2 == 1 & imgroup_v2 !=. & L.imgroup_v2 !=.
***********************************

generate NI_v2 = 0
replace NI_v2 = 1 if swiss == 1 & frombirth == 2
recode NI_v2 (0=.) if swiss == . | frombirth ==.
tab NI_v2 syear, missing
label define nis 0 "native" 1 "NI"
label values NI_v2 nis
tab NI_v2


*********************************
***Creating immigration group var
*********************************

generate imgroup_v2 = 999
replace imgroup_v2 = 1 if frombirth == 1
replace imgroup_v2 = 2 if NI_v2 == 1
replace imgroup_v2 = 3 if swiss !=1 & swiss !=.
tab imgroup_v2
label define group 1 "native" 2 "NI" 3 "NNI"
label values imgroup_v2 group
tab imgroup_v2 
recode imgroup_v2 (999=.)



**************************************************
******************IMPORTANT NOTE*****************
**************************************************

tab imgroup_v2 frombirth 
** there are some potential errors made in coding by SHP
* some IDs go from being NNI to N (especially children)
tab idpers if frombirth == 1 & imgroup_v2 == 3
** there is not much we can do about them because we don't which 
** info is true; whether they had Swiss citizenship from birth
** or whether they were NNIs that become NI
** what we know is that they are mostly children under 18:
tab age if frombirth == 1 & imgroup_v2 == 3
** so they will be excluded from the analysis - and the very few cases 
**                                we can just individually drop

gen disagree = 1 if frombirth == 1 & imgroup_v2 == 3
bysort idpers (disagree): replace disagree = disagree[1]
sort disagree idpers year2


** so this variable disagree indicates id numbers where this mistake has happened

tab imgroup_v2 frombirth 
tab imgroup_v2 frombirth if disagree != 1
********************************************************* 

* d160_ birth in Switzerland
* p05_  electoral status
* e16_ first language personal use
* e17_ second language personal use
* permit // permit type 
tab permit

tab d162_ // reception of Swiss nationality
* d164_  Since when in Switzerland (year)
tab d164_
* d163_ reception of nationality (age)
* d165_ Since when in Switzerland (age)

tab nat_1_ 
tab nat_2_ 
tab nat_3_ // first second third nationality

*********************************
** Region of origin for citizens:
*********************************
* reg_1_ reg_2_ reg_3_ // first second third region of origin

** For people who naturalise reg_1_ no longer shows origin thus we use 2
** But there are also some NIs that still keep their origin in 1 and put Swiss in 2
** So we need information from both variables for NI
gen origin1 = reg_1_

gen origin2 = reg_2_

	** there are some native Swiss with double citizenship who 
	** have put these two things in different orders so to be safe
	** I will code all native Swiss to have "Switzerland" in this var. 

gen origin = 99999
replace origin = 10  if frombirth == 1 & imgroup_v2 !=. 
//// Native Swiss are coded as Switzerland
replace origin = origin2 if frombirth !=1 & NI_v2 == 1 & imgroup_v2 !=.  
/// NIs get their region2
replace origin = origin1 if frombirth !=1 & NI_v2 == 1 & origin2 == 10 & imgroup_v2 !=. 
/// in case there were some NIs who put Swiss 2 we get info from 1
replace origin = origin1 if swiss !=1 & imgroup_v2 ==3 
/// and we get the info from 1 for NNIs. 

tab origin
recode origin (99999 =.) // these are observations where do not have info

label define regions2 10 "Swiss-N" 11 "N.Europe" 12 "E.Europe" ///
                     13 "C.Europe" 14 "W.Europe" 15 "SW.Europe" ///
					 16 "S.Europe" 17"SE. Europe" 20 "Africa" 30 "L.America" 31 "N.America" ///
					 40 "Asia" 50 "Oceania"
label values origin regions2


tab imgroup_v2 if origin == 10 

tab idpers if origin == 10 & imgroup_v2 == 3
tab idpers if origin == 10 & imgroup_v2 == 2
** the errors in these have to be hand-coded and corrected because there is 
** no systematic way to figure this out because
** these are people who change the order in 1 and 2

gen note = 1 if origin == 10 & imgroup_v2 == 3
gen note2 = 1 if origin == 10 & imgroup_v2 == 2

** after corrections, we need to balance the 4 or so cases again
replace NI_v2 = 1 if imgroup_v2 == 2

***********************************************************************
*** Creating a variable to capture years since Naturalisation date****
gen acquire = d162_

bysort idpers (disagree): replace disagree = disagree[1]

gen citsince = (syear - acquire)
tab citsince
** just three cases said the year after so this is -1, I recode them to 0


gen citsince_cat = 9999
replace citsince_cat = 0 if imgroup_v2 == 3
replace citsince_cat = 1 if citsince <=5
replace citsince_cat = 2 if citsince >6 & citsince <=10
replace citsince_cat = 3 if citsince >10 & citsince <=20
replace citsince_cat = 4 if citsince >20 & citsince <=77
replace citsince_cat = 5 if imgroup_v2 == 1
tab citsince_cat
recode citsince_cat (9999 =.) 

label define natural 0 "NNI" 1 "0-5 yers since Naturalisation" 2 "6-10" ///
                     3 "10-20" 4 "20+years" 5 "Native" 
label values citsince_cat natural


*********************************************************
*** Creating a variable to capture time since in CH 

gen inch = d164_
bysort idpers (inch): replace inch = inch[1]
gen inchsince = (syear-inch)
summ inchsince 
tab idpers if imgroup_v2 == 2 & inchsince <0
replace inchsince =0 if imgroup_v2 == 2 & inchsince <0
** there is one NI respondent case who says they came in 2003 but is in the panel before
** coding that to 0 when it is negative 
tab idpers if imgroup_v2 == 3 & inchsince <0
replace inchsince =. if imgroup_v2 == 3 & inchsince <0

gen inCHyears = 9999
replace inCHyears = 0 if inchsince <5 & inchsince>=0
replace inCHyears = 1 if inchsince >=5 & inchsince <10
replace inCHyears = 2 if inchsince >=10 & inchsince <20
replace inCHyears = 3 if inchsince >=20 & inchsince <=101
replace inCHyears = 4 if imgroup_v2 == 1
tab inCHyears
recode inCHyears (9999 =.) 
label define stay 0 "0-4 years in CH" 1 "5-9 years" 2 "10-20" ///
                     3 "20+ years" 4 "Native" 
label values inCHyears stay

******************************
** place of residence characteristic (at commune level)
summ com1_ com2_
tab com1_ 
tab com2_

***********************************************************
***********************************************************

gen non_dual = 9999
replace non_dual = 1 if frombirth == 1 & swiss == 1 & nat_1_ == 8100 & nat_2_ ==. & nat_3_ ==.
replace non_dual = 2 if frombirth == 1 & swiss == 1 & nat_2_ !=.
replace non_dual = 3 if imgroup_v2 == 2
replace non_dual = 4 if imgroup_v2 == 3
recode non_dual (9999=.)
label define gens 1 "Native-NonDual" 2 "NativeDual" 3 "NI" ///
                     4 "NNI"  
label values non_dual gens
tab non_dual

summ non_dual inCHyears citsince_cat

tab imgroup_v2 non_dual

***********************************
xtset idpers syear

** to be excluded from the sample:
tab idpers disagree if non_dual != L.non_dual & non_dual == 1 & non_dual !=. & L.non_dual !=.
gen disagree2 = 1 if non_dual != L.non_dual & non_dual == 1 & non_dual !=. & L.non_dual !=.

tab idpers if non_dual != L.non_dual & non_dual !=. & L.non_dual !=.
gen dualcorrect = 1 if non_dual != L.non_dual & non_dual !=. & L.non_dual !=. 

bysort idpers (dualcorrect): replace dualcorrect = dualcorrect[1]
sort dualcorrect idpers year2 

tab imgroup_v2 non_dual

***************************************
***Dependent Variable

** variable name: ext_efficacy (higher values mean higher efficacy)
* p03_ feeling about political influence (external efficacy)
sum p03_ 
tab p03_
** not available 10, 12, 13, 15, 16
generate ext_efficacy = p03_


****Other relevant variables***********

**variable name: democ_satis (Higher values more satisfied) 
* p02_ satisfaction with democracy
tab p02_ 
sum p02_
** not available 10, 12, 13, 15, 16
generate democ_satis = p02_

** variable name: pol_trust (higher values mean higher trust)
* p04_ trust in federal government
sum p04_ 
tab p04_
** not available 10, 12, 13, 15, 16
generate pol_trust = p04_

** variable name: political_participation (higher values more frequent)
*p06_  participation in federal polls
* not available 06, 10, 12,13, 15, 16
sum p06_
tab p06_
generate political_participation = p06_

*p11_ member of a political party (which)
** not available 10, 12, 13, 15, 16
tab p11_
*n43_ member of political party (active/passive/not member)
**Sympathizing with SVP
 p72_ // 2011 & 2014
 
** Left-right ideology
tab p10_ syear
generate left_right = p10_ 
tab left_right // higher values mean more to the right

** Generalised trust (in people)
tab p45_ //only available from 02
generate gen_trust = p45_
tab gen_trust // higher values mean more trust

** Work status
tab wstat 
* 1: active employed 2: unemployed 3: not in labour force

** Sex
tab sex 

generate gender = sex
recode gender (1=0) (2=1)
* 1:man 2: woman

gen woman = sex
recode woman (1=0) (2=1)
** Age (continous)
tab age

** Education (continous)
tab edyear // keeping the original variable for the moment
*alternatives: educat edcat edugr edgr isced 

** Political interest:
* p01_ interest in politics
tab p01_
generate pol_interest = p01_ // higher values indicate more interest

* ptotn_ yearly total personal income, net
** 
summ htyn_ // yearly household income, net
xtile income_h= htyn_, nquantile(10) 
tab income_h
tab ptotn_
xtile income=ptotn_, nquantile(10) /*recodification of income in quintiles*/
tab income if ptotn_ > 100000

corr income_h income

i16eqon // 
**** 
* r04_ participation in religious services (frequency)
** General trust in people p45_  //only available from 02


***************************************************
** Non-Citizen Voting Rights at the Local Level
***************************************************

*** The following code shows how the local voting rights variable in the analysis was created
*** Due to data restrictions, the municipal identifier variable of the respondents (ofs_) can not
*** be included in the deposited data set. It is available upon request from the FORS data centre
*** https://forscenter.ch/



* Generating municipal voting rights:
generate mvoting = 99
replace mvoting = 0 if canton == 1 // AG
replace mvoting = 0 if canton == 2 // AI
replace mvoting = 0 if canton == 4 // BE
replace mvoting = 0 if canton == 5 // BS
replace mvoting = 0 if canton == 6 // BL
replace mvoting = 0 if canton == 9 // GL
replace mvoting = 0 if canton == 12 // LU
replace mvoting = 0 if canton == 14 // NW
replace mvoting = 0 if canton == 15 // OW
replace mvoting = 0 if canton == 16 // SG
replace mvoting = 0 if canton == 17 // SH
replace mvoting = 0 if canton == 18 // S0
replace mvoting = 0 if canton == 19 // SZ
replace mvoting = 0 if canton == 20 // TG
replace mvoting = 0 if canton == 21 // TI
replace mvoting = 0 if canton == 22 // UR
replace mvoting = 0 if canton == 24 // VS
replace mvoting = 0 if canton == 25 // ZG
replace mvoting = 0 if canton == 26 // ZH

** Voting rights in all communes:

* FR - Fribourg (7) - 2006
replace mvoting = 0 if canton == 7 & syear <2006
replace mvoting = 1 if canton == 7 & syear >= 2006
* GE - Geneva (8) - 2005
replace mvoting = 0 if canton == 8 & syear <2005
replace mvoting = 1 if canton == 8 & syear >= 2005
* JU - Jura (11) - 1979 
replace mvoting = 1 if canton == 11
* NE - Neuchatel (13) - 1849
replace mvoting = 1 if canton == 13
replace mvoting = 0 if canton == 13 & syear == 1999
* VD - Vaud (23) - 2002
replace mvoting = 0 if canton == 23 & syear < 2002
replace mvoting = 1 if canton == 23 & syear >= 2002

** Not all but some communes:

* AR - Appenzell Aus (3)
replace mvoting = 33 if canton == 3

tab canton year if ofs_ == 3034 
replace canton = 3 if ofs_ == 3034 // correcting communes-canton match
tab canton year if ofs_ == 3023
tab canton year if ofs_ == 3025
replace canton = 3 if ofs_ == 3025 // correcting communes-canton match
tab canton year if ofs_ == 3036

replace mvoting = 0 if ofs_ == 3034 & syear <2014 
replace mvoting = 1 if ofs_ == 3034 & syear >= 2014
replace mvoting = 0 if ofs_ == 3023 & syear < 2002
replace mvoting = 1 if ofs_ == 3023 & syear >=2002
replace mvoting = 0 if ofs_ == 3025 & syear <2004
replace mvoting = 1 if ofs_ == 3025 & syear >=2004
replace mvoting = 0 if ofs_ == 3036 & syear <1999
replace mvoting = 1 if ofs_ == 3036 & syear >=1999

tab mvoting
replace mvoting = 0 if mvoting  == 33


* GR - Grisons (10)
replace mvoting = 66 if canton == 10

tab canton year if ofs_ == 3542 
tab canton year if ofs_ == 3921 
tab canton year if ofs_== 3781 
tab canton year if ofs_ ==  3721 
tab canton year if ofs_ == 3792 
tab canton year if ofs_ == 3703 
tab canton year if ofs_ == 3661
tab canton year if ofs_ == 3881 
tab canton year if ofs_ == 3673 
tab canton year if ofs_ == 3705 
tab canton year if ofs_ == 3861 
tab canton year if ofs_== 3662 
tab canton year if ofs_ == 3863 
tab canton year if ofs_== 3663 
tab canton year if ofs_ == 3672 
tab canton year if ofs_ == 3581 
tab canton year if ofs_ == 3762 
tab canton year if ofs_== 3640 
tab canton year if ofs_ == 3985 
tab canton year if ofs_ == 3669 
tab canton year if ofs_  == 3603 

replace mvoting = 0 if ofs_ == 3542 & syear <2014
replace mvoting = 1 if ofs_ == 3542 & syear >=2014
replace mvoting = 0 if ofs_ == 3921 & syear < 2012
replace mvoting = 1 if ofs_ == 3921 & syear >= 2012
replace mvoting = 0 if ofs_ == 3781 & syear < 2006
replace mvoting = 1 if ofs_ == 3781 & syear >= 2006
replace mvoting = 0 if ofs_ ==  3721 & syear < 2005
replace mvoting = 1 if ofs_ ==  3721 & syear >= 2005
replace mvoting = 0 if ofs_ == 3792 & syear < 2009
replace mvoting = 1 if ofs_ == 3792 & syear >= 2009
replace mvoting = 0 if ofs_ == 3703  & syear < 2012
replace mvoting = 1 if ofs_ == 3703 & syear >= 2012
replace mvoting = 0 if ofs_ == 3661  & syear < 2009
replace mvoting = 1 if ofs_ == 3661 & syear >= 2009
replace mvoting = 0 if ofs_ == 3881 & syear < 2002
replace mvoting = 1 if ofs_ == 3881 & syear >= 2002
replace mvoting = 0 if ofs_ == 3673  & syear < 2014
replace mvoting = 1 if ofs_ == 3673 & syear >= 2014
replace mvoting = 0 if ofs_ == 3705 & syear < 2007
replace mvoting = 1 if ofs_ == 3705 & syear >= 2007
replace mvoting = 0 if ofs_ == 3861 & syear < 2005
replace mvoting = 1 if ofs_ == 3861 & syear >= 2005
replace mvoting = 0 if ofs_ == 3662 & syear < 2012
replace mvoting = 1 if ofs_ == 3662 & syear >= 2012
replace mvoting = 0 if ofs_ == 3863 & syear < 2013
replace mvoting = 1 if ofs_ == 3863 & syear >= 2013

** Luzein (3891) has voting rights, year unknown
tab canton year if ofs_  == 3891 // 60 obs. (3 id)
replace mvoting = 0 if ofs_ == 3663 & syear < 2004
replace mvoting = 1 if ofs_ == 3663 & syear >= 2004
replace mvoting = 0 if ofs_ == 3672 & syear < 2012
replace mvoting = 1 if ofs_ == 3672 & syear >= 2012
replace mvoting = 0 if ofs_ == 3581 & syear < 2010
replace mvoting = 1 if ofs_ == 3581 & syear >= 2010
replace mvoting = 0 if ofs_ == 3762 & syear < 2014
replace mvoting = 1 if ofs_ == 3762 & syear >= 2014
replace mvoting = 0 if ofs_ == 3640 & syear < 2009
replace mvoting = 1 if ofs_ == 3640 & syear >= 2009
replace mvoting = 0 if ofs_ == 3985 & syear < 2009
replace mvoting = 1 if ofs_ == 3985 & syear >= 2009
** Surces (3543) has voting rights, year unknown
tab canton year if ofs_  == 3543 // 10 obs. (5 id)
replace mvoting = 0 if ofs_ == 3669 & syear < 2008
replace mvoting = 1 if ofs_ == 3669 & syear >= 2008
replace mvoting = 0 if ofs_ == 3603 & syear < 2012
replace mvoting = 1 if ofs_ == 3603 & syear >= 2012
tab mvoting
replace mvoting = 0 if mvoting  == 66
**
tab canton if mvoting == 99
tab ofs_ if mvoting == 99
sort mvoting
replace mvoting =. if mvoting == 99










